/**
 * @include "libs/jquery-1.3.2.js" 
 * @include "utils.js"
 * @include "map.js"  
 */

egm = {
	ini:function(d){
		$('body').attr('onUnload', 'm.exitMap();');
		egm.drawHTML(d);
		
		if(config.maximize){
			m.changeSize();
			$(window).resize(m.changeSize);
		}else{
			var height =  $('#'+d).height();
			var width = $('#'+d).width();
		
			$('#canvas_center').css('top', height/2 + 'px');
			$('#canvas_center').css('left', width/2 + 'px');
		
			$('#div_map').css('height', height + 'px');
			$('#div_map').css('width', width + 'px');
		
			$('#canvas_block').css('height', height + 'px');
			$('#canvas_block').css('width', width + 'px');
		
			$('#canvas').css('height', height + 'px');
			$('#canvas').css('width', width + 'px');
		}
		
		$('#canvas_block').animate({"opacity":0.5});
		$('#canvas').show();
	
		//events
		
		$("#share_link").click(m.toggleShare);
		$("#popup_share_button").click(m.hideShare);
	
		egm.applyEfectsLinks();
		
		m.ini();
		
		egm.ActivateGoogleAnalitycs();
		
	},
	
	drawHTML:function(d){
		var html = 	'<div id="canvas_center">'+
				'		<!-- Todos los popups ocultos aqui: -->'+
				'		<div id="popup_share">'+
				'			<div class="commonText" id="popup_share_text">Copia y pega este link para compartir lo que estas viendo:'+
				'				<br>'+
				'				<br>'+
				'				<span><input id="popup_share_textbox" class="inputbox" type="text" /></span>'+
				'			</div>'+
				'			<input id="popup_share_button" type="button" class="btn" value="Aceptar" />'+
				'		</div>'+
				'	</div>'+
				'	<div id="elements_hiddens">'+
				'		<div id="tb_seccion" class="tb_seccion">'+
				'			<div id="tb_check" class="tb_check">'+
				'				<input type="checkbox" checked="checked">'+
				'			</div>'+
				'			<div id="tb_img" class="tb_img">'+
				'				<img border="0" alt="" src="" title="" />'+
				'			</div>'+
				'			<div id="tb_text"  class="tb_text hand">'+
				'			</div>'+
				'			<div id="tb_div"  class="tb_div"></div>'+
				'		</div>'+
				'	</div>'+
				'	<div id="canvas">'+
				'		<div id="canvas_block"></div>'+
				'	<div id="logo-egm"><img /></div>'+
				'		<div id="tb_kmls">'+
				'			<div id="tb_press" class="hand"></div>'+
				'		</div>'+
				'		<div id="div_map"></div>'+
				'		<div id="div_foot">'+
				'			<div id="div_loading"><img id="img_loading" alt="loading..." title="loading..." src="img/egm/loading.gif"></div>'+
				'			<div id="div_powerBy">'+
				'				Power by <a href="http://code.google.com/intl/en/apis/maps/documentation/examples/index.html" target="_blank">Google Maps</a> & <br>Based on: <a href="http://code.google.com/p/easy-google-maps" target="_blank">Easy Google Maps</a>'+
				'			</div>'+
				'			<div id="div_links">'+
				'				<a href="http://code.google.com/p/easy-google-maps/" target="_blank" id="label_links" class="commonText">Link1</a>'+
				'			</div>'+
				'			<table id="table_foot" cellspacing="0" cellpadding="0">'+
				'				<tr>'+
				'					<td align="center">'+
				'						<table id="table_food_share" cellspacing="0" cellpadding="0">'+
				'							<tr>'+
				'								<td><div id="label_share" class="commonText">Comparte!:</div></td>'+
				'								<td>'+
				'									<div id="div_share_icons">'+
				'										<a target="_blank" rel="nofollow" id="share_link"><img class="hand" border="0" alt="Enviar via link!" src="img/egm/ico/url.gif" title="Enviar via link!" /></a>'+
				'										<a target="_blank" rel="nofollow" id="share_mail"	href=""><img border="0" alt="Enviar via mail!" src="img/egm/ico/mail.gif" title="Enviar via mail!" /></a>'+
				'										<a target="_blank" rel="nofollow" id="share_fb"		href=""><img border="0" alt="Compartir en Facebook!" src="img/egm/ico/facebook.png" title="Compartir en Facebook!" /></a>'+
				'										<a target="_blank" rel="nofollow" id="share_myspac" href=""><img border="0" alt="Compartir en MySpace" src="img/egm/ico/myspace.png" title="Compartir en MySpace" /></a>'+
				'										<a target="_blank" rel="nofollow" id="share_del"	href=""><img border="0" alt="Agregar a del.icio.us!" src="img/egm/ico/delicious.png" title="Agregar a del.icio.us!" /></a>'+
				'										<a target="_blank" rel="nofollow" id="share_google"	href=""><img border="0" alt="Agregar a Google Bookmarks!" src="img/egm/ico/google.png" title="Agregar a Google Bookmarks!" /></a>'+
				'										<a target="_blank" rel="nofollow" id="share_live"	href=""><img border="0" alt="Agregar a Live!" src="img/egm/ico/live.png" title="Agregar a Live!" /></a>'+
				'									</div>'+
				'								</td>'+
				'							</tr>'+
				'						</table>'+
				'					</td>'+
				'				</tr>'+
				'			</table>'+
				'		</div>'+
				'	</div>';
				
		document.getElementById(d).innerHTML = html;
		
	},
	
	applyEfectsLinks:function(){
		$("#share_link").animate({"opacity":0.5});
		$("#share_mail").animate({"opacity":0.5});
		$("#share_fb").animate({"opacity":0.5});
		$("#share_del").animate({"opacity":0.5});
		$("#share_google").animate({"opacity":0.5});
		$("#share_myspac").animate({"opacity":0.5});
		$("#share_live").animate({"opacity":0.5});
		
		
		$("#share_link").hover(egm.turnonLink,egm.turnoffLink);
		$("#share_mail").hover(egm.turnonLink,egm.turnoffLink);
		$("#share_fb").hover(egm.turnonLink,egm.turnoffLink);
		$("#share_del").hover(egm.turnonLink,egm.turnoffLink);
		$("#share_google").hover(egm.turnonLink,egm.turnoffLink);
		$("#share_myspac").hover(egm.turnonLink,egm.turnoffLink);
		$("#share_live").hover(egm.turnonLink,egm.turnoffLink);
	},
	
	turnonLink:function(){
		$("#"+this.id).animate({"opacity":1});
	},
	turnoffLink:function(){
		$("#"+this.id).animate({"opacity":0.5});
	},
	
	ActivateGoogleAnalitycs:function(){
		if(config.gaKey.length>0 && document.location.hostname!="localhost"){
			var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
			utils.loadJavascript(gaJsHost + "google-analytics.com/ga.js");
			
			try {
				var pageTracker = _gat._getTracker(config.gaKey);
				pageTracker._trackPageview();
			} catch(err) {};
		}
	}
};





